<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link href="/resource/css/assets/bootstrap.min.css" rel="stylesheet"/>
    <link href="/resource/css/style.css" rel="stylesheet"/>
    <link href="/resource/css/assets/codemirror.css" rel="stylesheet">
    <link rel="stylesheet" href="/resource/css/assets/ace.min.css"/>
    <link rel="stylesheet" href="/resource/font/css/font-awesome.min.css"/>
    <!--[if lte IE 8]>
    <link rel="stylesheet" href="/resource/css/assets/ace-ie.min.css"/>
    <![endif]-->
    <script src="/resource/js/jquery-1.9.1.min.js"></script>
    <script src="/resource/js/assets/bootstrap.min.js"></script>
    <script type="text/javascript" src="/resource/js/Validform.min.js"></script>
    <script src="/resource/js/assets/typeahead-bs2.min.js"></script>
    <script src="/resource/js/lrtk.js" type="text/javascript"></script>
    <link rel="stylesheet" href="/resource/common/layui/css/layui.css" media="all"/>
    <title>管理员</title>
</head>
<body>
<div class="page-content clearfix">
    <div class="administrator">
        <div class="d_Confirm_Order_style">
            <div class="search_style">
                <ul class="search_content clearfix">
                    <li><label class="l_f">用户名</label>
                        <input type="text" id="userName" class="text_add" autocomplete="off"
                               style=" width:200px"/>
                    </li>
                    <li><label class="l_f">时间</label>
                        <input type="text" id="time" class="text_add laydate-icon" autocomplete="off"
                               style="width:200px"/>
                    </li>
                    <li style="width:200px;">
                        <button type="button" class="btn_search search"><i class="fa fa-search"></i>查询</button>
                        <button type="button" class="btn_search revocation">
                            <i class="layui-icon layui-icon-refresh"></i>撤销
                        </button>
                    </li>
                </ul>
            </div>
            <!--操作-->
            <div class="border clearfix">
       <span class="l_f">
        <a class="btn btn-danger del"><i class="fa fa-trash"></i> 批量删除</a>
       </span>
            </div>
            <div class="clearfix administrator_style" id="administrator">
                <div class="compete_list" id="testIframe">
                    <table id="logTables" data-mobile-responsive="true" lay-filter="logTables"></table>
                </div>
            </div>
        </div>
    </div>

</div>

</body>
</html>
<script type="text/html" id="operate">
    <a title="删除" class="btn btn-xs btn-warning" lay-event="del"><i class="fa fa-trash  bigger-120"></i></a>
</script>
<script type="text/javascript" src="/resource/common/layui/layui.js"></script>
<script type="text/javascript" src="/resource/js/assets/laydate/laydate.js"></script>
<script type="text/javascript">
    layui.use(['table', 'layer', 'laydate', 'form'], function () {
        var table = layui.table,
            $ = layui.$,
            layer = layui.layer,
            laydate = layui.laydate,
            form = layui.form;
        var tableIns = table.render({
            elem: '#logTables'
            , even: true
            , url: '/log/log.do' //数据接口
            , method: 'get'
            , page: true //开启分页
            , id: 'tableId'
            , limits: [10, 15, 30]
            , limit: 15
            , cols: [
                [ //表头
                    {'type': 'checkbox', 'fixed': 'left'}
                    , {field: 'time', title: '记录时间'}
                    , {field: 'operation', title: '记录内容'}
                    , {field: 'userName', title: '操作用户'}
                    , {title: '操作', toolbar: '#operate', 'fixed': 'right'}
                ]
            ]
        });
        //搜索
        $('.search').on('click', function () {
            console.log("搜索执行")
            active.reload()
        });
        //撤销
        $(".revocation").on('click', function () {
            $("#userName").val("");
            $("#time").val("");
            form.render();
            active.reload()
        });
        $('.del').on('click', function () {
            var datas = table.checkStatus("tableId").data;
            console.log(datas)
            if (datas.length == 0) {
                layer.alert("请选择数据后再进行操作！");
            } else {
                var ids = new Array();
                for (d in datas) {
                    ids.push(datas[d].id);
                }
                dellog(ids.toString());
            }
        });
        //监听工具条
        table.on('tool(logTables)', function (obj) {
            var data = obj.data;
            console.log(data);
            if (obj.event === 'del') {
                //删除
                dellog(data.id);
            }
        });

        active = {
            reload: function () {
                var userName = $("#userName").val();
                var time = $("#time").val();
                //执行重载
                table
                    .reload('tableId', {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                        , where: {
                            userName: userName,
                            time: time,
                        }
                    });
            }
        };

        //删除函数
        function dellog(id) {
            layer.confirm('是否删除?', function (index) {
                $.ajax({
                    url: "/log/log.do",
                    type: "post",
                    data: {_method: "DELETE", "ids": id},
                    dataType: "json",
                    success: function (result) {
                        if (!result.status) {
                            layer.msg(result.msg, {time: 2000});
                            return false;
                        }
                        layer.msg("删除成功!", {time: 1000});
                        active.reload();
                    }
                });
                layer.close(index);
            })
        }
    });

</script>
<script type="text/javascript">
    $(function () {
        $("#administrator").fix({
            float: 'left',
            //minStatue : true,
            skin: 'green',
            durationTime: false,
            spacingw: 50,//设置隐藏时的距离
            spacingh: 270,//设置显示时间距
        });
    });
    //初始化宽度、高度
    $(".widget-box").height($(window).height() - 215);
    $(".table_menu_list").width($(window).width() - 260);
    $(".table_menu_list").height($(window).height() - 215);
    //当文档窗口发生改变时 触发
    $(window).resize(function () {
        $(".widget-box").height($(window).height() - 215);
        $(".table_menu_list").width($(window).width() - 260);
        $(".table_menu_list").height($(window).height() - 215);
    })
    laydate({
        elem: '#time',
        event: 'focus',
    });
</script>

